package com.example.demo;

import com.example.demo.mapper.EmpMapper;
import com.example.demo.model.Emp;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@SpringBootApplication
@Slf4j
@MapperScan("mapper")
public class DemoApplication implements CommandLineRunner {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Autowired
	EmpMapper empMapper;
	@Override
	public void run(String... args) throws Exception {
		log.info("out");
		Emp emp = Emp.builder().name("张三").job("主管")
				.salary(Money.of(CurrencyUnit.of("CNY"), 20.0)).build();

//		empMapper.save(emp);
//		empMapper.findEmps().forEach(e->log.info(e.toString()));
		RowBounds rowBounds = new RowBounds(1,2);
		empMapper.findAllWithRowBounds(rowBounds).forEach(e->log.info(e.toString()));
		empMapper.findAllWithParam(2, 2)
				.forEach(c -> log.info("Page(1) emp {}", c));
		List<Emp> list = empMapper.findAllWithParam(2, 2);
		PageInfo page = new PageInfo(list);
		log.info("PageInfo: {}", page);
	}



}
